﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using Microsoft.Office.Interop.Outlook;

namespace FogOutlook {
	public partial class ReadMailGroupRibbon {
		private void ReadMailGroupRibbon_Load(object sender, RibbonUIEventArgs e) {

		}

		private void reportBug_Click(object sender, RibbonControlEventArgs e) {
			if(!CheckConnect())
				return;
			var window = ThisAddIn.app.ActiveWindow();
			if(window is Inspector) {
				Inspector ins = (Inspector)window;
				MailItem mi = ins.CurrentItem as MailItem;
				if(mi != null) {
					//BugReportForm brf = new BugReportForm(mi);
					//brf.ShowDialog();
					ThisAddIn.BugTracker.OpenBugReport(mi, ThisAddIn.GetSenderSMTPAddress(mi)); // This sucks :/
				}
			}
		}

		private bool CheckConnect() {
			if(!ThisAddIn.IsConnected) {
				if(!ThisAddIn.IsConnecting)
					bugTrackerGroup_DialogLauncherClick(null, null);
				return ThisAddIn.WaitConnect();
			}
			return true;
		}

		private void bugTrackerGroup_DialogLauncherClick(object sender, RibbonControlEventArgs e) {
			using(LoginForm lf = new LoginForm()) {
				if(lf.ShowDialog() == System.Windows.Forms.DialogResult.OK)
					ThisAddIn.TryConnect(false, lf.username.Text, lf.password.Text, lf.btURL.Text, lf.btType.Text);
			}
		}
	}
}
